<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 100px;
        float: left;
        height: 100px;
        border: solid 1px #000;
        margin-right: 10px;
      }
    </style>
  </head>
  <body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <script>
      var divs = document.querySelectorAll('div')
      for (var i = 0; i < divs.length; i++) {
        divs[i].onclick = function () {
          for  (var j = 0; j < divs.length; j++) {
            divs[j].style.backgroundColor = ''
          }
          this.style.backgroundColor = 'pink'
        }
      }
    </script>
  </body>
</html>
